package com.shanghaiyimu.yimiyangche.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shanghaiyimu.yimiyangche.R;
import com.shanghaiyimu.yimiyangche.bean.OilBen;

import java.util.List;

/**
 * Author:ShangHaiYiMu
 * Time:2017/7/14   12:00
 * Description:GoodsListAdapter
 */

public class GoodsListAdapter extends BaseAdapter{
    private Context context;
    private List<OilBen> datas;

    public GoodsListAdapter(Context context, List<OilBen> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        return datas!=null?datas.size():0;
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.goods_list_lv_item,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        OilBen oilBen = datas.get(position);
        holder.name.setText(oilBen.getName());
        holder.cont.setText(""+oilBen.getKucun());
        holder.price.setText("当前价格："+oilBen.getPrice());
        holder.pingjia.setText("总评价："+oilBen.getPingjia());
        holder.xiaoliang.setText("已售："+oilBen.getXiaoliang());
        return convertView;
    }
    static class ViewHolder{
        private TextView name,cont,price,pingjia,xiaoliang;

        public ViewHolder(View view) {

            name = (TextView) view.findViewById(R.id.name_list_goods);
            cont = (TextView) view.findViewById(R.id.goods_list_cont);
            price = (TextView) view.findViewById(R.id.songjia_goods_list_item);
            pingjia = (TextView) view.findViewById(R.id.zongpingjia_good_lv);
            xiaoliang = (TextView) view.findViewById(R.id.xiaoliang_good_lv);

        }
    }

}
